package org.struts.util;

import java.lang.reflect.Field;


import javax.servlet.http.HttpServletRequest;

import org.struts.action.ActionForm;

public class FullForm {
	
	public static ActionForm fullForm(HttpServletRequest req,String className){
		ActionForm form = null;
		try {
			Class clazz = Class.forName(className);
			form = (ActionForm) clazz.newInstance();
			Field[] fileds = clazz.getDeclaredFields();
			for(Field field:fileds){
				field.setAccessible(true);
				
				if(field.getType().getName().equals("int")){
					//int类型
					field.set(form,Integer.parseInt(req.getParameter(field.getName())+""));
				}else{
					field.set(form,req.getParameter(field.getName()));
				}
				field.setAccessible(false);
			}
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return form;
	}
}
